unit CasualPawnWithBackground;

interface

uses Pawn, Graphics, Types, SysUtils;

type
 TCasualPawnWithBackground = class(TPawnWithImage)
 public
  constructor Create(Dim: integer; Color: TColor; Value: Integer);
  procedure Draw(Canvas: TCanvas); override;
 end;

implementation

procedure TCasualPawnWithBackground.Draw(Canvas: TCanvas);
var
 tX, tY: integer;
begin
 inherited Draw(Canvas);

 Canvas.Font.Color := clWhite;
 Canvas.Font.Size := 10;

 tX := (OldPosition.X+1 + OldPosition.X + round(Dimension / 2.2)) div 2 - Canvas.TextWidth(IntToStr(Value)) div 2;
 tY := (OldPosition.Y+1 + OldPosition.Y + round(Dimension / 2.2)) div 2 - Canvas.TextHeight(IntToStr(Value)) div 2;

 Canvas.TextOut(tX, tY, IntToStr(Value));
end;


constructor TCasualPawnWithBackground.Create(Dim: integer; Color: TColor; Value: Integer);
var
 layer: TBitmap;
begin
 inherited Create(dim, Color, Value, 'graph\baseball.bmp');  

 layer := TBitmap.Create;
 layer.Width := img.Width;
 layer.Height := img.Height;
 layer.Canvas.Brush.Color := clFuchsia;
 layer.Canvas.FillRect(Rect(0,0, layer.Width, layer.Height));
 layer.Canvas.Brush.Color := Color;
 layer.Canvas.Pen.Width := 0;
 layer.Canvas.Pen.Color := Color;
 layer.Canvas.Ellipse(0,0, layer.Width, layer.Height);

 layer.TransparentColor := clFuchsia;
 layer.Transparent := true;

 DrawTransparency(img.Canvas, 0, 0, layer, 45);
 layer.Free;
end;

end.
